;function debug(o){
	var debug = [];
	for(var p in o){
		debug.push(p+": "+o[p]);
	}
	return debug.join("\n");
};
function getTopWindow(){
	var win = window;
	while(win != window.parent){
		win = window.parent;
	}
	return win;
};
function getWidth(f){
	return document.documentElement.clientWidth;
};

function getHeight(){
	return document.documentElement.clientHeight;
};
function getPageSize() 
{
	var body = document.documentElement || document;
	var pageDimensions = [0,0]; 

	var widths = [body.offsetWidth, body.scrollWidth];
	var heights = [body.offsetHeight, body.scrollHeight];
	for(var p in widths){
		pageDimensions[0] = Math.max(pageDimensions[0], widths[p]);
	}
	for(var p in heights){
		pageDimensions[1] = Math.max(pageDimensions[1], heights[p]);
	}
	return pageDimensions;
};
function getById(id){
	return document.getElementById(id);
};

String.prototype.trim = function()
{
	return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
};
String.prototype.startWith = function(str)
{
	if(!str) return false;
	if(this.length >= 1){
		return this.substring(0,1) == str;
	}
	return false;
};
String.prototype.escapeHTML = function(){
	return this.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/'/g, '\'').replace(/"/g, "\"");
};
String.prototype.encodeHTML = function(){
	return this.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
};
String.prototype.decodeHTML = function(){
	return this.replace(/&amp;/g,'&').replace(/&lt;/g,'<').replace(/&gt;/g,'>');
};
/**
 * 四舍五入
 * @param point 保留小数位数
 */
Number.prototype.round = function(point){
	var f = this;
	var p = Math.pow(10, point);
	return Math.round(f * p) / p;
};
/**
 * 直接舍弃多余的小数
 * @param point 保留小数位数
 */
Number.prototype.floor = function(point){
	var f = this;
	var p = Math.pow(10, point);
	return Math.floor(f * p) / p;
};
/**
 * 将数值转换为字符串，并指定强制保留的小数位（不够补0）
 * @param point 保留小数位数
 */
Number.prototype.format = function(point){
	var vs = this+"";
	var hasPoint = false;
	var len = point;
	if(vs.indexOf(".") != -1){
		var scale = vs.split(".")[1].length;
		if(scale >= point){
			return this.round(point);
		}
		hasPoint = true;
		len = point - scale;
	}
	var zeros = new Array(len);
	for(var i=0; i<len; i++){zeros.push(0);}
	if(hasPoint){return vs+zeros.join('');}
	else{return vs+"."+zeros.join('');}
};
function isArray(v){
	return Object.prototype.toString.apply(v) === '[object Array]';
};
function isFunction(v){
	return Object.prototype.toString.apply(v) === '[object Function]';
};

/**
 * 属性复制
 * @param src 源对象
 * @param dest 目标对象
 * @return dest
 */
function Extends(src, dest){
	var b = false;
	
	if( src && dest && typeof(dest) == "object"){
		for( var p in src ) {
			if( !dest[p] )
				dest[p] = src[p];
		}
	}
	return dest;
};

//以POST方式提交数据
var openPostWindow = postData = function(url, dataObj, name){
	var _name = name || "_self";
	var tempForm = document.createElement("form");
	tempForm.id="tempForm1";
	tempForm.method="post";
	tempForm.action=url;
	tempForm.target=_name;
	
	if(dataObj){
		for(var p in dataObj){
			var hideInput = document.createElement("input");
			hideInput.type="hidden";
			hideInput.name= p;
			hideInput.value= dataObj[p];
			tempForm.appendChild(hideInput);
		}
	};
	document.body.appendChild(tempForm);
	tempForm.submit();
	document.body.removeChild(tempForm);
};

function GetAttribute( element, attName, valueIfNull )
{
	var oAtt = element.attributes[attName] ;
	if ( oAtt == null || !oAtt.specified )
		return valueIfNull ? valueIfNull : '' ;
	var oValue = element.getAttribute( attName, 2 ) ;
	if ( oValue == null )
		oValue = oAtt.nodeValue ;
	return ( oValue == null ? valueIfNull : oValue ) ;
};

function SetAttribute( element, attName, attValue )
{
	if ( attValue == null || attValue.length == 0 )
		element.removeAttribute( attName, 0 );	
	else
		element.setAttribute( attName, attValue, 0 );
};

Function.prototype.createDelegate = Function.prototype.proxy = function(obj){
    var method = this;
    return function() {
        return method.apply(obj || window, arguments);
    };
};
function center(el){
	var dw = document.documentElement.clientWidth;
	var dh = document.documentElement.clientHeight;
	if(el.clientWidth > (dw*0.8)){
		el.style.width = dw*0.8+"px";
	}
	if(el.clientHeight > (dh*0.8)){
		el.style.height = dh*0.8+"px";
	}
	var mw = dw * 0.50 - (el.clientWidth/2);
	var mh = dh * 0.50 - (el.clientHeight/2);
	var px = Math.round(mw / dw * 100);
	var py = Math.round(mh / dh * 100);
	el.style.left = px + "%";
	el.style.top = py + "%";
};
function addEvent(el, ename, fn){
	if(window.addEventListener){ // Mozilla, Netscape, Firefox
		if(ename.startWith("on")){
			ename = ename.substring(2);
		}
		el.addEventListener('click', fn, false);
	}else{
		if(!ename.startWith('on')){
			ename = 'on'+ename
		}
		el.attachEvent('onclick', fn);
	}
};

function removeEvent(el, ename, fn){
	if(window.removeEventListener){ // Mozilla, Netscape, Firefox
		if(ename.startWith("on")){
			ename = ename.substring(2);
		}
		el.removeEventListener('click', fn, false);
	}else{
		if(!ename.startWith('on')){
			ename = 'on'+ename
		}
		el.detachEvent('onclick', fn);
	}
};

function openWindow(url, target){
	var _target = target || "_blank";
	window.open(url, _target, "resizable=yes,fullscreen=yes,scrollbars=yes;");
};


//页面掩饰
var Mask = {
	visible:false,
	showIndex: 0,
	hideIndex: 0,
	show : function(text){
		this.showIndex += 1;
		var doShow = function(){
			if(this.showIndex == this.hideIndex){
				return false;
			}
			var _text = text || "正在处理...";
			document.getElementById("loading-text").innerHTML = _text;
			if(! this.visible){
				var pageDimensions = getPageSize();
				document.getElementById("loading-mask").style.width = pageDimensions[0]+"px";
				document.getElementById("loading-mask").style.height = pageDimensions[1]+"px";
				document.getElementById("loading-mask").style.display = "block";
				document.getElementById("loading").style.display = "block";
				center(document.getElementById("loading"));
				this.visible = true;
			}
		};
		setTimeout(doShow.proxy(this), 2000);
	},hide : function(){
		this.hideIndex += 1;
		if(this.visible){
			document.getElementById("loading-mask").style.display = "none";
			document.getElementById("loading").style.display = "none";
			this.visible = false;
		}
	}
};
//AJAX回调
var Ajax = {
	"callback" : function(result, success, error){
		success = isFunction(success) ? success : null;
		error = isFunction(error) ? error : null;
		var _success = success || Ajax.success;
		var _error = error || Ajax.error;
		var json = result;
		if(typeof(json) == "string"){
			try{
				json = eval("("+json+")");
			}catch(e){
				json = result;
			}
		};
		if(json && json.success === false){
			_error(json.data, json);
			return false;
		};
		var data = null;
		if(json){
			data = json.data;
		}
		_success(data, json);
	},
	"success" : function(msg){
		Mask.hide();
		var _msg = msg || "操作成功！";
		showTip(_msg);
	},
	"error" : function(msg){
		Mask.hide();
		var _msg = msg || "对不起，操作失败！";
		showTip(_msg);
	}
};
 /**
  * 显示TIP
  * @author WuBo
  * @CreateDate 2010-5-8
  * @version 1.0
  */
function showTip(value, time){
	var win = getTopWindow();
	if(win != window && isFunction(win.showTip)){
		win.showTip(value, time);
		return;
	}
	function remove(div){
		try{
			div.style.isplay="none";
			document.body.removeChild(div);
			div = null;
		}catch(e){}
	};
	var div = document.createElement("DIV");
	div.innerHTML = value;
	div.style.display = "block";
	div.style.visibility = "hidden";
	div.className = "tip_div";
	document.body.appendChild(div);
	center(div);
	div.style.visibility = "visible";
	var t = time || 3000;
	addEvent(div, "click", function(){remove(div);});
	if(typeof(jQuery) === 'undefined'){
		setTimeout(function(){
			remove(div);
		}, t);
	}else{
		jQuery(div).fadeIn(200).delay(t).fadeOut(400, function(){
			remove(div);
		});
	}
};
Alert = function(msg){
	showTip(msg);
}
function SearchEvent(){
    func=SearchEvent.caller;
    while(func!=null){
        var arg0=func.arguments[0];
        if(arg0){
            if(arg0.constructor==Event)
                return arg0;
        }
        func=func.caller;
    }
    return null;
};
/*
 * 描述：跨浏览器的设置 innerHTML 方法
 *       允许插入的 HTML 代码中包含 script 和 style
 * 作者：Edwardtian tianpf@gmail.com
 * 日期：2006-09-01
 * 参数：
 *    el: 合法的 DOM 树中的节点
 *    htmlCode: 合法的 HTML 代码
 * 经测试的浏览器：ie5+, firefox1.5+, opera8.5+
 */
function setInnerHTML(el, htmlCode) {
    var ua = navigator.userAgent.toLowerCase();
    if (ua.indexOf('msie') >= 0 && ua.indexOf('opera') < 0) {
        htmlCode = '<div style="display:none">for IE</div>' + htmlCode;
        htmlCode = htmlCode.replace(/<script([^>]*)>/gi,
                                    '<script$1 defer>');
        el.innerHTML = '';
        el.innerHTML = htmlCode;
        el.removeChild(el.firstChild);
    } else {
    	var el_next = el.nextSibling;
        var el_parent = el.parentNode;
        if(el_parent)el_parent.removeChild(el);
        el.innerHTML = htmlCode;
        if(el_parent){
	        if (el_next) {
	            el_parent.insertBefore(el, el_next)
	        } else {
	            el_parent.appendChild(el);
	        }
        }
    }
};
/*
 * 全选或全不选
 * @param el 全选对象
 * @param cbxName 多选框的name
 */
function checkAll(el, cbxName){
	var es = document.getElementsByName(cbxName);
	var check = el.checked;
	for(var i=0; i<es.length; i++){
		es[i].checked = check;
	}
};

function uncheckAll(cbxName){
	cbxName = cbxName || "checkedAll";
	var es = document.getElementsByName(cbxName);
	for(var i=0; i<es.length; i++){
		es[i].checked = false;
	}
}
function checkValue(els, value){
	if(! els)return false;
	var arr = new ArrayList();
	arr.addAll(value);
	for(var i=0; i<els.length; i++){
		if(arr.contains(els[i].value)){
			els[i].checked = true;
		}
	}
}
function checkReverse(cbxName){
	cbxName = cbxName || "checkedAll";
	var es = document.getElementsByName(cbxName);
	for(var i=0; i<es.length; i++){
		es[i].checked = ! es[i].checked;
	}
}
function checkedIfAll(cbxName, cbxAllName){
	var es = document.getElementsByName(cbxName);
	var sa = document.getElementById(cbxAllName);
	for(var i=0; i<es.length; i++){
		if(! es[i].checked){
			sa.checked = false;return;
		}
	}
	sa.checked = true;
}
/*
 * 从源Select复制填充到目标Select
 */
function copyFillSelect(source, target, cache){
	if(!cache || target.options.length == 0){
		target.options.length = 0;
		var options = source.options;
		for(var i=0; i<options.length; i++){
			var option = options[i];
			target.options.add(new Option(option.text, option.value));
		}
	}
	target.selectedIndex = source.selectedIndex;
}
function selectValue(el, value){
	if(! el)return false;
	var arr = new ArrayList();
	arr.addAll(value);
	for(var i=0; i<el.options.length; i++){
		var option = el.options[i];
		if(arr.contains(option.value)){
			option.selected = true;
		}
	}
}
//得到选中的值
function getChecked(name){
	var els = document.getElementsByName(name);
	if(els.length < 1)return null;
	var type = els[0].type;
	var result = null;
	var isCbx = ( type == "checkbox" );
	if(isCbx){
		result = [];
	}
	for(var i=0; i<els.length; i++){
		if(els[i].checked){
			if(isCbx){
				result.push(els[i].value);
			}else{
				result = els[i].value;break;
			}
		}
	}
	return result;
};
//根据传入值选中多选框或单选框
function setChecked(name, values, reset){
	var _reset = reset || true;
	var els = document.getElementsByName(name);
	for(var i=0; i<els.length; i++){
		if(_reset){
			els[i].checked = false;
		}
		if(isArray(values)){
			for(var j=0; j<values.length; j++){
				if(els[i].value == values[j]){
					els[i].checked = true;break;
				}
			}
		}else{
			els[i].checked = ( els[i].value == values );
		}
	}
};
//为已选控件加色
function setColor(name, values, reset){
	var _reset = reset || true;
	var els = document.getElementsByName(name);
	var getSpan = function(el){
		var sib = el.nextSibling;
		if(!sib)return null;
		return sib.tagName == "SPAN" ? sib : getSpan(sib);
	};
	for(var i=0; i<els.length; i++){
		var el = getSpan(els[i]);
		if(_reset){
			el.className = "";
		}
		if(isArray(values)){
			for(var j=0; j<values.length; j++){
				if(els[i].value == values[j]){
					el.className = "checked-style";
				}
			}
		}else{
			if(els[i].value == values){
				el.className = "checked-style";
			}
		}
	}
};

DateUtil = (function(){
	var pad = function(n) {
        return n < 10 ? "0" + n : n;
    };
	function getYear(date, l){
		if(l){return date.getFullYear();}else{return date.getYear();}
	};
	function getMonth(date, l){
		if(l){return pad(date.getMonth()+1);}else{return date.getMonth()+1;}
	};
	function getDay(date, l){
		if(l){return pad(date.getDay()+1);}else{return date.getDay()+1;}
	};
	function getHour(date, l){
		if(l){return pad(date.getHours());}else{return date.getHours();}
	};
	function getMinutes(date, l){
		if(l){return pad(date.getMinutes());}else{return date.getMinutes();}
	};
	function getSeconds(date, l){
		if(l){return pad(date.getSeconds());}else{return date.getSeconds();}
	};
	function date2YYMMDD(date){
		if(typeof(date) == 'string' || typeof(date) == 'number'){
			date = new Date(date);
		}
		var l = true;
		return getYear(date, l)+"-"+getMonth(date, l)+"-"+getDay(date, l);
	};
	function date2YYMMDDHHMI(date){
		if(typeof(date) == 'string' || typeof(date) == 'number'){
			date = new Date(date);
		}
		var l = true;
		return getYear(date, l)+"-"+getMonth(date, l)+"-"+getDay(date, l)+" "+getHour(date, l)+":"+getMinutes(date, l);
	};
	function date2YYMMDDHHMISS(date){
		if(typeof(date) == 'string' || typeof(date) == 'number'){
			date = new Date(date);
		}
		var l = true;
		return getYear(date, l)+"-"+getMonth(date, l)+"-"+getDay(date, l)+" "+getHour(date, l)
			+":"+getMinutes(date, l)+":"+getSeconds(date, l);
	};
	function str2date(str){
		var datetime = str.split(/[　 ]+/);
		var date = datetime[0];
		var time = datetime[1];
		var params = [];
		if(date){
			params = params.concat(date.split("-"));
		}
		if(time){
			params = params.concat(time.split(":"));
		}
		var date = eval("new Date("+params.join(",")+")");
		return date;
	};
	return {
		"date2YYMMDD":date2YYMMDD,
		"date2YYMMDDHHMI": date2YYMMDDHHMI,
		"date2YYMMDDHHMISS": date2YYMMDDHHMISS,
		"str2date": str2date
	}
})();

/**
 * 脚本登录
 * 当访问页面有jquery.thickbox库时，弹出登录对话框，否则转向登录页面
 * @param content (string) 后台返回的登录页面相对路径（用于多登录页面）
 * @param success (boolean) 被拦截的Ajax请求的成功回调函数
 * @param scope (object) 作用域，通常是被拦截Ajax请求的作用域
 */
function scriptLogin(content, success, scope, type){
	var _type = "";if(type){_type = "&type="+type;};
	var scope = scope || window;
	var dataType = scope.dataType;
	var _finalize = null;
	if(typeof(tb_show) != 'undefined'){
		hideBox();
		showBox(path+content+"?script=true"+_type+"&KeepThis=true&TB_iframe=true&height=400&width=600", "用户登录");
		_finalize = function(){
			tb_remove();
		}
	}else{
		//var url = document.location;
		//window.location.href = path+content+"?script=true"+_type+"&url="+url;
		var div = document.createElement("DIV");
		div.className = "div-mask";
		var iframe = document.createElement("IFRAME");
		iframe.src = path+content+"?script=true"+_type;
		iframe.className = "div-mask-content";
		div.appendChild(iframe);
		document.body.appendChild(div);
		_finalize = function(){
			div.removeChild(iframe);
			document.body.removeChild(div);
		}
	}
	window.scriptLoginCallback = function(data, json){
		if(_finalize){_finalize();};
		if(success){
			if(dataType == 'text' || dataType == "html"){
				json = json.toString();
			}
			success.call(scope, json)
		}
		window.scriptLoginCallback = undefined;
	}
};
/**
 * 为了当异步请求时，前台能够感知session过期，改变jQuery的Ajax默认行为
 * 当Session过期时，后台权限控制可能会拦截此Ajax请求，要求重新通过认证（调用scriptLogin方法提供认证入口），
 * 认证成功后将继续执行前面被拦截的Ajax请求
 * @author WuBo 2012-02-23 
 */
if(typeof(jQuery) != 'undefined'){
 	if(typeof(jQuery.ajax) != 'undefined'){
 		jQuery.originAjax = jQuery.ajax;
 		jQuery.ajax = function(options){
 			if(typeof options == "object"){
 				var _beforeSend = options.beforeSend;
 				options.beforeSend = function(xhr){
 					if(_beforeSend){
 						_beforeSend.call(this, xhr);
 					}
 					xhr.setRequestHeader("RequestType","request-in-script");
 				}
 				var _dataType = "json";
 				if(options.dataType){_dataType = options.dataType.toLowerCase();};
 				var isScriptResult = false;
 				var completeHandled = 0;
 				var resultHolder = null;
 				var _success = options.success;
 				var _complete = options.complete;
 				options.complete = function(XHR, ts){
 					if(_complete){
 						_complete.call(this, XHR, ts);
 					}
					var resultType = XHR.getResponseHeader("ResultType");
					if(resultType == '_script_login_json_result'){
						isScriptResult = true;
					}
 					if(isScriptResult){
						Mask.hide();
						this.dataType = _dataType;
						scriptLogin(XHR.responseText, _success,  this);
 					}else if(ts == "success"){
						if(resultHolder){
	 						if(_success){
	 							_success.call(this, resultHolder.data, resultHolder.ts);
	 						}
	 					}
 					}
 					completeHandled = 1;
 				};
 				options.success = function(data, ts){
 					if(completeHandled === 1){
 						if(isScriptResult){
 							Mask.hide();
 							this.dataType = _dataType;
 							scriptLogin(data, _success, this);
	 					}else{
	 						if(_success){
	 							_success.call(this, data, ts);
	 						}
	 					}
 					}else{
 						resultHolder = {data:data, ts: ts};
 					}
 				};
 			}
 			jQuery.originAjax(options);
 		};
 	}
};
/**
 * 一个简单的ArrayList
 * 如果传入的是简单类型，则删除方法删除的元素可能非期望值，除非List中元素不重复
 * @author WuBo
 */
function ArrayList(){
	var increase = 10;
	var array = [];
	var size = 0;
	var index = 0;
	var _add = function(e){
		array.push(e);
		return index++;
	};
	this.add = function(e){
		return _add(e);
	};
	this.addAll = function(e){
		var len = arguments.length;
		if(len == 1){
			var e = arguments[0];
			if($.isArray(e)){
				for(var i=0; i<e.length; i++){
					_add(e[i]);
				}
			}else{
				_add(e);
			}
		}else{
			for(var i=0; i<arguments.length; i++){
				_add(arguments[i]);
			}
		}
	};
	this.remove = function(e){
		var idx = 0;
		var found = false; //是否找到
		for(var i=0;i<array.length;i++){
			if(array[i] === e){
				idx = i;
				found = true;
				break;
			}
		}
		if(found){
			this.removeIndex(idx);
			return true;
		}
		return false;
	};
	this.removeIndex = function(idx){
		if(idx == array.length-1){
			array[idx] = undefined;
		}else{
			for(;idx<array.length-1;idx++){
				array[idx] = array[idx+1];
			}
		}
		index--;
		if((array.length - index) > increase){
			var temp = array;
			array = [array.length - increase];
			for(var i=0;i<temp.length;i++){
				array[i] = temp[i];
			}
			index = array.length;
		}
	};
	this.contains = function(e){
		for(var i=0;i<array.length;i++){
			if(array[i] === e){
				return true;
			}
		}
		return false;
	};
	this.indexOf = function(e){
		for(var i=0;i<array.length;i++){
			if(array[i] === e){
				return i;
			}
		}
		return -1;
	};
	this.get = function(idx){
		return array[idx];
	};
	this.size = function(){
		return index;
	};
	this.toArray = function(){
		return array.slice(0, array.length);
	};
}
/**
 * LinkedHashMap 一个简单的有序HashMap实现
 * @author WuBo
 */
function LinkedHashMap(){
	var entryList = new ArrayList();
	var keyMap = {};
	this.put = function(key, value){
		var index = keyMap[key];
		if(index){
			entryList.removeIndex(index);
		}
		index = entryList.add({key:key, value:value});
		keyMap[key] = index;
	};
	this.remove = function(key){
		var index = keyMap[key];
		if(index){
			keyMap[key] = undefined;
			return entryList.removeIndex(index);
		}
		return false;
	};
	this.get = function(key){
		var entry = entryList.get(keyMap[key]);
		if(entry){
			return entry.value;
		}
		return null;
	};
	this.containsKey = function(key){
		return !! keyMap[key];
	};
	this.keySet = function(){
		var vArray = entryList.toArray();
		var result = [];
		for(var p in vArray){
			result.push(vArray[p].key);
		}
		return result;
	};
	this.valueSet = function(){
		var vArray = entryList.toArray();
		var result = [vArray.length];
		for(var p in vArray){
			result.push(vArray[p].value);
		}
		return result;
	};
	this.entrySet = function(){
		return entryList.toArray();
	};
	this.size = function(){
		return entryList.size();
	};
}

$(document).ready(function(){
	jQuery.fn.extend({
		/**
		 * 使表格的列可调整宽度
		 * 参数类型：Object
		 * 可用选项：
		 * showResizeBar: boolean，默认：true 显示调整宽度条，如果表格列与列之间本身有边框，请设为false
		 * tableWidthFixed: boolean，默认：true 表格宽度是否固定，当为true时，整个表格的宽度会改变，否则会调整其他列的宽度
		 * excludeIndexes: array 不改变宽度的列索引，从0开始
		 */
		"setResizable": function(params){
			var _params = params || {};
			var showResizeBar = typeof _params.showResizeBar == 'boolean' ? _params.showResizeBar : true;
			var tableWidthFixed = typeof _params.tableWidthFixed == 'boolean' ? _params.tableWidthFixed : true;
			var excludeIndexes = _params.excludeIndexes || [];
			var ths = this;
			var len = ths.length;
			ths.each(function(i){
				var resizeBar = $(this).attr("resizeBar");
				if(resizeBar){return;}
				for(var idx in excludeIndexes){
					if(i == excludeIndexes[idx]){
						return;
					}
				}
				if(showResizeBar){//是否显示改变大小的竖条
					var br = this.style.borderRight;
					this.style.borderRight = "1px solid black";
					if(! br){br="0px none"};
					$(this).attr("resizeBar", br);
				}
				$(this).css({"margin":"0 0", "padding":"0 0"});
				var divWrapperStyle = "display:table;";
				var divLeftStyle = "display:table-cell;";
				var divRightStyle = "display:table-cell;";
				if($.browser.msie && ($.browser.version == '6.0' || $.browser.version == '7.0')){
					divWrapperStyle = '';
					divLeftStyle = "float:left;";
					divRightStyle = "float:right;";
				}
				var div = $("<div class='drag-wrapper' style='width:100%;height:100%;"+divWrapperStyle+"'></div>");
				var textWrapper = $("<div class='text-wrapper' style='"+divLeftStyle+"width:98%;height:100%;'></div>");
				$(this).wrapInner(textWrapper);
				$(this).wrapInner(div);
				$(this).find(".drag-wrapper").append("<div class='drag-el' style='"+divRightStyle+"height:100%;width:2px;'><span style='visibility:hidden;'>&nbsp;</span></div>");
			});
			$(".drag-el").css({"cursor": "w-resize"}).each(function(){
				$(this).bind("mousedown", function(event){
					var oleft = event.pageX;
					var thEl = $($(this).context.parentNode.parentNode);
					var thWidth = thEl.width();
					if(!tableWidthFixed){
						var tableEl = thEl.parents("table");
						var tableWidth = tableEl.width();
					}
					
					$(document).css({"cursor": "w-resize"}).bind("mousemove", function(event){
						var left = event.pageX;
						var move = left-oleft;
						thEl.width(thWidth + move);
						if(!tableWidthFixed){
							tableEl.width(tableWidth + move);
						}
					});
				})
				$(document).bind("mouseup",function(event){
					 $(this).css({"cursor": "default"}).unbind("mousemove");
				});
			});
			return this;
		},
		/**
		 * 移除表格列可调整宽度功能，即抵消setResizable的操作
		 */
		"removeResizable": function(){
			var ths = this;
			var len = ths.length;
			ths.each(function(i){
				if(i==(len-1))return;
				var rb = $(this).attr("resizeBar");
				if(rb){
					this.style.borderRight = rb;
					$(this).css({"border-right": rb}).removeAttr("resizeBar");
					var innerEl = $(".text-wrapper > *", this);
					var len = $(".text-wrapper > *", this).length;
					if(len == 0){
						innerEl = $(document.createTextNode($(".text-wrapper").html()));
					}
					innerEl.replaceAll($(".drag-wrapper", this));
				}
			});
			return this;
		},
		/**
		 * 使表头点击即可排序，表头TH或TD需要有sort属性
		 * 参数类型：Object
		 * 可用选项：
		 * ascChar: string，默认：▲ 升序时显示的字符
		 * descChar: string，默认：▼ 降序时显示的字符
		 * onclick: function 当点击表头时，回调的函数，
		 * 函数可用参数: 
		 * sort:String sort属性的值
		 * asc: boolean 是否为升序
		 * obj: Object 排序对象
		 */
		"setSortable": function(params){
			var _params = params || {};
			var ascChar = _params.ascChar || "<span class=\"sortasc\">&nbsp;</span>";
			var descChar = _params.descChar || "<span class=\"sortdesc\">&nbsp;</span>";
			var onclick = _params.onclick || jQuery.noop;
			var transChar = function(str, o, n){
				return str.replace(o, n)
			};
			var SortManager = {};
			this.each(function(){
				var sort = $(this).attr("sort");
				if(sort){
					var text = $(this).text();
					//设置初始排序样式
					if(_params.sort == sort){
						$(this).html(text+(_params.asc ? ascChar : descChar));
					}
					var sortId = transChar(sort, ".", "-");
					var span = $("<span></span>");
					span.attr("id", "sort-wrapper-"+sortId);
					span.attr("sort", sort);
					
					$(this).wrapInner(span);
					SortManager[sort] = {
						source: $("#sort-wrapper-"+sortId),
						text: text,
						asc : true
					};
					$("#sort-wrapper-"+sortId).css({"cursor": "pointer"}).bind("click", function(){
						var _sort = $(this).attr("sort");
						//清理其他排序样式
						for(var p in SortManager){
							var _obj = SortManager[p];
							_obj.source.html(_obj.text);
						}
						var _text = SortManager[_sort].text;
						var _asc = SortManager[_sort].asc;
						if(_asc){
							$(this).html(_text + ascChar);
							SortManager[_sort].asc = false;
						}else{
							$(this).html(_text + descChar);
							SortManager[_sort].asc = true;
						}
						//执行分页查询
						onclick(_sort, _asc, SortManager[_sort]);
					});
				}
			});
			return this;
		},
		"showLoadingIcon":function(){
			this.html($("#loading-img").html());
		},
		/**
		 * 将文本框变为只能输入数字的数字输入框
		 * @param maxLen 最大允许整数位数（-1为不限制）
		 * @param pointMaxLen 最大允许小数位数（-1为不限制）
		 */
		"numberInput": function(maxLen, pointMaxLen){
			var ml = maxLen || -1;
			var pml = pointMaxLen || 0;
			$(this).keydown(function(e){
				var keyCode = 0;
				var shiftKey = false;
				if ($.browser.msie) {// 判断浏览器
					keyCode = event.keyCode;
					shiftKey = event.shiftKey;
                } else {
                	keyCode = e.which || e.keyCode;
					shiftKey = e.shiftKey;
                }
                
				if(pml == 0 && ml > 0){
					if(this.value.length >= ml && ((keyCode >= 48 && keyCode <= 57) 
                		|| (keyCode >= 96 && keyCode <= 105))){
						return false;
					}
				}
				
                if ( (!shiftKey && keyCode >= 48 && keyCode <= 57) 
                	|| (keyCode >= 96 && keyCode <= 105) 
                	|| (keyCode == 8 || keyCode == 16 || keyCode == 36 
                	|| keyCode == 37 || keyCode == 39 || keyCode == 46) ) {
                	return true;
                } else if(pml >= 0 && (keyCode == 110 || (keyCode == 190 && ! shiftKey))){
                	return true;
                }else{
                	return false;
                }
        	}).focus(function() {
        		this.style.imeMode='disabled'; // 禁用输入法,禁止输入中文字符
        	});
         	$(this).keyup(function(e){
         		var pidx = this.value.indexOf(".");
         		if(pidx != -1){
         			var integerPart = this.value.substring(0, pidx);
         			var pointPart = this.value.substring(pidx+1);
         			
         			if(ml != -1 && integerPart.length > ml && this.value !== '0'){
         				integerPart = integerPart.substring(0, ml);
         				this.value = integerPart+"."+pointPart;
         			}
         			if(pml != -1 && pointPart.length > pml){
         				pointPart = pointPart.substring(0, pml);
         				this.value = integerPart+"."+pointPart;
         			}
         		}else{
         			if(ml != -1 && this.value.length > ml){
         				this.value = this.value.substring(0, ml);
         			}
         		}
         	});
        	return this;
		}
	});
});